from datetime import datetime
from django.contrib.auth.models import AbstractUser
from django.db import models

GENDER_CHOICES = (
    ('male', '男'),
    ('female', '女')
)

class BaseModel(models.Model):
    add_time = models.DateField(default=datetime.now, verbose_name='添加时间')

    class Meta:
        abstract = True #不会生成表

class UserProfile(AbstractUser):
    nick_name = models.CharField(max_length=50, verbose_name="昵称", default='')
    birthday = models.DateField(verbose_name='生日', null=True, blank=True)
    gender = models.CharField(verbose_name='性别', choices=GENDER_CHOICES, max_length=6)
    address = models.CharField(max_length=100, verbose_name='地址', default='')
    mobile = models.CharField(max_length=11, unique=True, verbose_name='手机号码')
    image = models.ImageField(upload_to='head_image/%Y/%m', default='default.jpg')

    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        if self.nick_name:
            return self.nick_name
        else:
            return self.username

'''
启动项目时使用自定义用户模型
如果你准备启动一个新的项目，强烈推荐你设置一个自定义的用户模型，即使默认的用户模型对你来说已经足够了。这个模型的行为与默认用户模型相通，
但是你能在未来需要的时候自定义它：
from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    pass
'''